<?php
$page=$_GET['page']==""?0:$_GET['page'];
$keyword="";
$keyword=$keyword!=""?$keyword:$_GET['bKeyword'];
$keyword=$keyword!=""?$keyword:$_GET['mKeyword'];

$type=$_GET["type"]==""?"":$_GET["type"];
$sql=" FROM tbl_product WHERE 1";
if($keyword!="")
	$sql.=" AND `name` LIKE '%$keyword%'";
if($type!="")
	$sql.=" AND `product_type_id`=$type";
$cres=mysql_query("SELECT COUNT(*) $sql") or dieN(mysql_error());
while($crow=mysql_fetch_array($cres))
	$cpage=$crow[0];
if($cpage>0)
{
	$res=mysql_query("SELECT * $sql ORDER BY `name` ASC LIMIT ".($page*20).",20") or dieN(mysql_error());
	$i=0;
	$totalpage=floor($cpage/20+1);

	echo "<table border='0' cellspacing='0' cellpadding='0' style='width:100%'>";
	
	$pager="
		<tr>
			<td colspan='2' align='center' style='font-size:12px;background-color:#eeeeee' valign='middle'>";
	if($rowProductType)
		$pager.="<span style='float:right;font-size:12px;text-transform:uppercase;background-color:#ff8201;color:white;padding:4px 10px'>$rowProductType[name]</span>";
	
	
	$pager.="Trang ".($page+1)." / ".$totalpage."&nbsp;&nbsp;<span style='font-weight:bold'>";		
	for($i=0;$i<$totalpage;$i++)
	{
		if($i!=$page)
			$pager.="<span style='font-size:18px'>|</span>&nbsp;&nbsp;<a title='Xem trang ".($i+1)."' href='index.php?zone=searchproduct&bKeyword=$keyword&type=$type&page=$i'>".($i+1)."</a>&nbsp;&nbsp;";
		else
			$pager.="<span style='font-size:18px'>|</span>&nbsp;&nbsp;<a title='Xem trang ".($i+1)."' href='#' style='color:red'>".($i+1)."</a>&nbsp;&nbsp;";
	}
	$pager.="	</span>	
			</td>
		</tr>";
	
	echo $pager;
	echo "<tr><td>&nbsp;</td></tr>";
	while($row=mysql_fetch_array($res))
	{	
		if($row["image"]=="")
			$src="images/productbrowser_noimage.jpg";
		else
		{
			$o_src=$src="_thumbs/images/product/$row[image]";
			if(!file_exists($src))
				$src="images/productbrowser_noimage.jpg";
		}	
		$detail=strip_tags($row['detail']);
		$detail=substr($detail,0,200);	
		$pos=strrpos($detail," ");
		if($pos!==false);
			$detail=substr($detail,0,$pos);
		echo "
		<tr>
			<td style='width:162px' valign='top'>
				<a href='?zone=product&id=$row[id]' title='$row[quote]'>
					<table cellspacing='0' style='padding: 0pt; border: medium none; margin: 0pt;width:100%; border-collapse: collapse;'>
						<tbody style='padding: 0pt; border: medium none; margin: 0pt;'>
							<tr style='padding: 0pt; border: medium none; margin: 0pt; height: 10px;'>
								<td>
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt; font-size: 0pt; background: url(images/rounded_white.png) repeat scroll 0px 0px transparent; width: 10px;'>
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt; font-size: 0pt; background: url(images/rounded_white.png) repeat scroll 0px -40px transparent;  width: 10px;'>
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt; font-size: 0pt; background: url(images/rounded_white.png) repeat scroll 10px 0px transparent; width: 10px;'>
								</td>
								<td>
								</td>
							</tr>
							<tr style='padding: 0pt; border: medium none; margin: 0pt; height: auto;'>
								<td>
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt; font-size: 0pt; background: url(images/rounded_white.png) repeat scroll 0px -80px transparent; '>
								</td>						
								<td style='padding: 0pt; border: medium none; margin: 0pt; position: relative; background-color:#FFFFFF;' valign='bottom' align='center'>
									<img width='160px' title='$o_src' src='$src' alt='&nbsp;'/>						
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt; font-size: 0pt; background: url(images/rounded_white.png) repeat scroll 10px -80px transparent; '>
								</td>
								<td>
								</td>
							</tr>
							<tr style='padding: 0pt; border: medium none; margin: 0pt;height: 10px;'>
								<td>
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt; font-size: 0pt; background: url(images/rounded_white.png) repeat scroll 0px -30px transparent; '>
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt;  background: url(images/rounded_white.png) repeat scroll 0px -70px transparent;'>							
								</td>
								<td style='padding: 0pt; border: medium none; margin: 0pt; line-height: 0pt; font-size: 0pt; background: url(images/rounded_white.png) repeat scroll 10px -30px transparent; '>
								</td>
								<td>
								</td>
							</tr>
						</tbody>
					</table>
				</a>
				<br>
			</td>
			<td align='left' valign='top' style='padding:5px'>
				<a href='?zone=product&id=$row[id]'>
					<span style='color:blue'>$row[name]</span>
				</a>
				<br>
				$detail
				
			</td>
			</tr>
		<tr>
			<td colspan='2' align='right'>
				<a href='?zone=product&id=$row[id]' title='Xem chi tiết sản phẩm: $row[name]' style='font-style:italic'>
					Xem chi tiết
				</a>
			</td>
		</tr>";
		$i++;
	}
	echo "<tr><td>&nbsp;</td></tr>";
	echo $pager;
	echo "<tr><td>&nbsp;</td></tr>";
	echo "</table>";
}
else 
{
	echo "<br>Rất tiếc! Không tìm thấy sản phẩm theo yêu cầu của bạn.<br><br><br><br><br><br><br><br><br><br><br>";
}
?>